﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="MvcMembership.Controllers" %>
<asp:Content ID="content" ContentPlaceHolderID="MainContent" runat="server">

<% var user = ViewData["User"] as MembershipUserAndRolesViewData; %>
<h2 class="MvcMembership">User Details For "<% =user.User.UserName%>"</h2>
<h3 class="MvcMembership"><% =Html.ActionLink<MembershipAdministrationController>( x => x.Index( null, null ), "<< Return to Membership Administration" )%></h3>

<% using( Html.Form( "MembershipAdministration", "SaveExistingUser" ) ){ %>
<fieldset class="MvcMembership">
	<legend>User's Details</legend>

	<div>
	<label>User Name</label>
	<div><% =user.User.UserName %></div>
	<% =Html.Hidden( "UserName", user.User.UserName ) %>
	</div>

	<div>
	<label>Provider User Key</label>
	<div><% =user.User.ProviderUserKey %></div>
	</div>

	<div>
	<label for="Email">Email Address</label>
	<% =Html.TextBox( "Email", user.User.Email, new { size = 32, maxlength = 256 } ) %>
	</div>

	<div>
	<label for="Comment">Comment</label>
	<% =Html.TextBox( "Comment", user.User.Comment, new { size = 32, maxlength = 256 } )%>
	</div>

	<div>
	<label for="IsApproved">Is Approved</label>
	<div><input type="checkbox" id="IsApproved" name="IsApproved" <% =user.User.IsApproved ? "checked=\"checked\"" : "" %> /></div>
	</div>

	<hr />

	<div>
	<label>Created</label>
	<div><% =user.User.CreationDate.ToString( "M/d/yyyy h:mm:ss tt" )%></div>
	</div>

	<div>
	<label>Last Login</label>
	<div><% =user.User.CreationDate != user.User.LastLoginDate ? user.User.LastLoginDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Logged In" %></div>
	</div>

	<div>
	<label>Last Activity</label>
	<div><% =user.User.CreationDate != user.User.LastActivityDate ? user.User.LastActivityDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Active" %> (<% =user.User.IsOnline ? "Online" : "Offline" %>)</div>
	</div>

	<div>
	<label>Last Lockout</label>
	<div><% =( user.User.LastLockoutDate == DateTime.MinValue ? user.User.LastLockoutDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Locked Out" ) %></div>
	<% if( user.User.IsLockedOut ){ %>
	<div><% =Html.ActionLink<MembershipAdministrationController>( x => x.UnlockUser( (Guid)user.User.ProviderUserKey ), "(Unlock User)" )%></div>
	<% } %>
	</div>

	<div><% =Html.SubmitButton( "submitUpdateUserDetails", "Update User Details" ) %></div>

</fieldset>
<% } %>

<% if (user.RolesEnabled) { %>
<fieldset class="MvcMembership">
	<legend>User's Roles</legend>

	<% if( user.AllRoles.Count > 0 ){ %>
	<% foreach( string role in user.AllRoles ){ %>
	<div>
		<% if( user.UsersRoles.Contains(role) ){ %>
		(<% =Html.ActionLink<MembershipAdministrationController>( x => x.RemoveUserFromRole( (Guid)user.User.ProviderUserKey, role ), "-" )%>)
		<% }else{ %>
		(<% =Html.ActionLink<MembershipAdministrationController>( x => x.AddUserToRole( (Guid)user.User.ProviderUserKey, role ), "+" )%>)
		<% } %>
		<% =Html.ActionLink<MembershipAdministrationController>( x=>x.Role(role), role ) %>
	</div>
	<% } %>
	<% }else{ %>
	<div>No roles have been added to the system yet.</div>
	<% } %>

</fieldset>
<% } %>

<% using( Html.Form( "MembershipAdministration", "ResetPassword" ) ){ %>
<fieldset class="MvcMembership">
	<legend>Reset User's Password</legend>

	<% =Html.Hidden( "UserName", user.User.UserName ) %>

	<div>
	<label>Last Password Change</label>
	<div><% =user.User.CreationDate != user.User.LastPasswordChangedDate ? user.User.LastPasswordChangedDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Changed Password" %></div>
	</div>

	<div>
	<label>Password Question</label>
	<% if( !string.IsNullOrEmpty( user.User.PasswordQuestion) ){ %>
	<div><% =user.User.PasswordQuestion %></div>
	<% }else{ %>
	<div><em>No password question set.</em></div>
	<% } %>
	</div>

	<div>
	<label for="PasswordAnswer">Password Answer</label>
	<% =Html.TextBox("PasswordAnswer", new { size = 32, maxlength = 128 })%>
	</div>

	<div><% =Html.SubmitButton( "submitResetPassword", "Reset Password" ) %></div>

</fieldset>
<% } %>

<% using( Html.Form( "MembershipAdministration", "ChangePassword" ) ){ %>
<fieldset class="MvcMembership">
	<legend>Change User's Password</legend>

	<% =Html.Hidden( "UserName", user.User.UserName ) %>

	<div>
	<label>Last Password Change</label>
	<div><% =user.User.CreationDate != user.User.LastPasswordChangedDate ? user.User.LastPasswordChangedDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Changed Password" %></div>
	</div>

	<div>
	<label for="OldPassword">Old Password</label>
	<% =Html.Password( "OldPassword", new { size = 32 } ) %>
	</div>

	<div>
	<label for="NewPassword">New Password</label>
	<% =Html.Password( "NewPassword", new { size = 32 } ) %>
	</div>

	<div>
	<label for="NewPasswordConfirm">Confirm New Password</label>
	<% =Html.Password( "NewPasswordConfirm", new { size = 32 } ) %>
	</div>

	<div><% =Html.SubmitButton( "submitChangePassword", "Change Password" ) %></div>

</fieldset>
<% } %>

<fieldset class="MvcMembership">
	<legend>Permanently Delete User</legend>
	<p><% =Html.ActionLink( "Delete User", "DeleteUser", "MembershipAdministration", new{ id = (Guid)user.User.ProviderUserKey } ) %> (This action cannot be undone.)</p>
</fieldset>

</asp:Content>